package com.javaoopthree;

import java.util.Scanner;

public class User {
    public int id;
    public String uName;
    public String password;

    public User(){


    }
    public User(String uName, String password) {
        this.uName = uName;
        this.password = password;
    }


    //登录
    public User toLogin(Scanner scanner,User[] users){
        System.out.println("请输入用户名：");
        String name = scanner.next();
        System.out.println("请输入密码");
        String password = scanner.next();
        User user = null;
        for (int i = 0; i < users.length; i++) {
            if(users[i] !=null && name.equals(users[i].uName) && password.equals(users[i].password)){
                user=users[i];
                break;
            }
        }
        return user;
    }

     //注册
    public int addUser(User[] users,Scanner scanner){
        int num=0;
        System.out.println("请输入用户名：");
        String name = scanner.next();
        System.out.println("请输入密码");
        String password = scanner.next();
        boolean b = checkName(users, name);
        if(!b){
            User user  = new User(name,password);
            for (int i = 0; i < users.length; i++) {
                if(users[i]==null){
                    users[i]=user;
                    num=1;
                    break;
                }
            }
        }else {
            System.out.println("用户名存在,重新录入...");
        }
        return num;
    }

    //重名验证
    public boolean checkName(User[] users,String name){
        boolean isOk=false;
        for (int i = 0; i < users.length; i++) {
            if(users[i]!=null && users[i].uName.equals(name)){
                isOk=true;
                break;
            }
        }
        return isOk;
    }


     //点餐


     //付款

}
